package com.misoo.ex09;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class Ex09Activity extends Activity {
	public static final int CHG_ID = Menu.FIRST;
	public static final int EXIT_ID = Menu.FIRST + 1;
	private String[] data = {" Item-1", " Item-2", " Item-3"};
	TextView tv;
	LinearLayout layout1, layout2;
	boolean selection = true;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflate = (LayoutInflater)
        		getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layout1 = (LinearLayout)inflate.inflate(R.layout.main, null);
        setContentView(layout1);
        
        TextView tx = (TextView)findViewById(R.id.tx);
        tx.setBackgroundResource(R.drawable.bg_6);
        tx.setTextColor(Color.WHITE);
        
        layout2 = (LinearLayout)inflate.inflate(R.layout.list, null);
        ListView lv = (ListView)layout2.findViewById(R.id.list);
        lv.setBackgroundResource(R.drawable.desc_new);
        
        ArrayAdapter<String> adapter = new ArrayAdapter<String>
        	(this, android.R.layout.simple_list_item_1,data);
        lv.setAdapter(adapter);        
    }
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		super.onCreateOptionsMenu(menu);
		menu.add(0, CHG_ID, 0, "Change");
		MenuItem im = menu.findItem(CHG_ID);
		im.setIcon(R.drawable.chang_im);
		menu.add(0,EXIT_ID,1,"Exit");
		im.setIcon(R.drawable.exit_menu_item);
		return true;
	}
	/* (non-Javadoc)
	 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch(item.getItemId()){
		case CHG_ID:
			selection = !selection;
			if(selection)
				setContentView(layout1);
			else
				setContentView(layout2);
			break;
		case EXIT_ID:
			finish();
			break;
		}
		return super.onOptionsItemSelected(item);
	}
    
    
}